<?php

//Copiar todo este conteudo sem alterar, usar Copy e Paste

//////////////////////////////////////////////////////////////////////////////
//                                                                          //
//                                                                          //
//Quebrar a Rotina lda. NIF 507969499                                       //
//www.pagamentoseguros.com, geral@pagamentoseguros.com                      //
//                                                                          //
//Parte deste cdigo  opensource Joomla e Virtuemart.                      //
//Restante cdigo tem direitos reservados embora seja de utilizao livre.  //
//Est proibida a sua adulterao.                                          //
//Ningum pode obter lucros reivindicando a autoria deste cdigo.           //
//////////////////////////////////////////////////////////////////////////////


defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
global $mosConfig_live_site, $mosConfig_absolute_path, $sess, $ps_vendor_id,
	$VM_LANG, $mosConfig_smtpauth, $mosConfig_mailer, $vmLogger,
	$mosConfig_smtpuser, $mosConfig_smtppass, $mosConfig_smtphost, $mosConfig_mailfrom, $mosConfig_fromname;

$order_id = $db->f("order_id");
$order_value = $db->f("order_total");

include($mosConfig_absolute_path.'/multibanco/multibanco.cfg.php');
     
       $ent_id = $entidade;
       $subent_id = $subentidade;
       $subent_id = sprintf('%03u', $subent_id);


echo '<img src= "http://www.pagamentoseguros.com/multibanco/multibanco.jpg" height="97" width="108" align="left" alt="Success" border="0" style="float: left;" /><br>';

echo '<div style="TEXT-ALIGN: justify"> <strong> O pagamento por multibanco  feito em qualquer caixa multibanco.<br><br>Tambm pode pagar pelo seu homebanking na opo de pagamento de servios.<br><br><br><br><br></strong></div>';

echo '<div style="TEXT-ALIGN: center"> <strong>A expedio ser efectuada aps o pagamento.<br></strong></div>';
echo '<div style="TEXT-ALIGN: center"> <strong><br>Imprima esta pgina ou tome nota dos dados abaixo.<br></strong></div>';
echo '<div style="TEXT-ALIGN: center"> <strong><br>Encomenda N '.$order_id.'<br><br></strong></div>';


$file='http://www.pagamentoseguros.com/multibanco/getref.php';
$file.='?entidade='.$ent_id;
$file.='&subentidade='.$subent_id;
$file.='&valor='.$order_value;
$file.='&encomenda='.$order_id;

//echo $file."<br>";

$lines = file($file);

//echo "lines 0 deu ".$lines[0]."<br>";

$len=strlen($lines[0]);

$entidade = substr($lines[0], 0, 5);
//echo "entidade ".$entidade."<br>";

$ref = substr($lines[0], 6, 9);
//echo "referencia ".$ref."<br>";

$valor = substr($lines[0], 16, $len-16);
//echo "valor ".$valor."<br>";


       echo '<img src="http://www.pagamentoseguros.com/multibanco/multibanco.jpg" height="69" width="77" align="center" alt="Success" border="0" style="float: center;" /><br>';
      
       
       echo '<br><div style="IMAGE-ALIGN: center"><strong>   Entidade:    </strong>'.$ent_id;
       echo '</div>';
       echo '<div style="TEXT-ALIGN: center"><strong>   Referncia:</strong>'.$subent_id." ".substr($ref, 3, 3)." ".substr($ref, 6, 3);
       echo '</div>';
       echo '<div style="TEXT-ALIGN: center"><strong>   Valor:</strong>'.str_replace(".", ",", $order_value);
       echo ' Euro';
       echo '</div>';
 
      


	
		 	
	// modif
	if(is_null($sess)){
		$Itemid = 1;
	} else {
		$Itemid = $sess->getShopItemid();
	}
	$url = $mosConfig_live_site."/index.php?option=com_virtuemart&page=account.order_details&order_id=".$order_id."&Itemid=$Itemid";
		
	
/* MAIL BODY */

	$message = $VM_LANG->_HI. ' ' . $dbbt->f("first_name") .($dbbt->f("middle_name")?' '.$dbbt->f("middle_name") : '' ). ' '  . $dbbt->f("last_name") . ",\n\n";

	$message .= $VM_LANG->_PHPSHOP_ORDER_MBCODE_SEND_MSG_1 .$order_id ."\n\n";

     

	$message .= "Entidade: " .$ent_id."\n";
	$message .= "Referencia: " .$subent_id." " .substr($ref, 3, 3)." " .substr($ref, 6, 3)."\n";
	$message .= "Valor: " .str_replace(".", ",", $order_value)."\n\n";

	
         $message .= $VM_LANG->_PHPSHOP_ORDER_MBCODE_SEND_MSG_2;


      
         $message .= "\n____________________________________________________________\n\n";
	$message .= $VM_LANG->_PHPSHOP_ORDER_STATUS_CHANGE_SEND_MSG_3."\n";
	$message .= $url;
	$message .= "\n\n____________________________________________________________\n";
	$message .= $store_name."\n";
         $message .= $mosConfig_live_site."\n";
	$message .= $store_mail;


	$mail_Body = html_entity_decode($message);

         $mail_Subject = str_replace( "{order_id}", $order_id, html_entity_decode($VM_LANG->_PHPSHOP_MBCODE_SEND_SUBJ));

	
	$result = vmMail( $store_mail,  $store_name,
	$dbbt->f("user_email"), $mail_Subject, $mail_Body, '' );

	/* Send the email */
	//modif
	if(!is_null($sess)){
		if ($result) {
			$vmLogger->info( $VM_LANG->_PHPSHOP_DOWNLOADS_SEND_MSG. " ". $dbbt->f("first_name") . " " . $dbbt->f("last_name") . ", ".$dbbt->f("user_email") );
		} else {
			$vmLogger->warning( $VM_LANG->_PHPSHOP_DOWNLOADS_ERR_SEND.' '. $dbbt->f("first_name") . " " . $dbbt->f("last_name") . ", ".$dbbt->f("user_email")." (". $result->ErrorInfo.")" );
		}
	}

?>
